//ExtendFunctions一些为了编程方便而增加的函数

function getNumFromInput(id)        //获取一个元素的value并将其转换为int类型
{
    return parseInt(document.getElementById(id).value);
}

function getValueFromDoc(id)
{
    return document.getElementById(id).value;
}

function  setValueFromDoc(id,value)
{
    document.getElementById(id).value = value;
}

function getFloatFromInput(id)
{
    return parseFloat(document.getElementById(id).value);
}

function setInner(id,text)
{
    document.getElementById(id).innerHTML = text;
}

function getGLFromDoc()             //从文档中获取gl上下文
{
    canvas = document.getElementById('VolRenderCanvas');
    gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
    return gl;
}

function colord2h(r,g,b)
{
    var rString = Math.floor(r).toString(16);
    if(rString.length==1)rString = "0"+rString;
    var gString = Math.floor(g).toString(16);
    if(gString.length==1)gString = "0"+gString;
    var bString = Math.floor(b).toString(16);
    if(bString.length==1)bString = "0"+bString;

    return "#"+ rString+gString+bString;
}

function colorh2d(HString)
{
    var result = new Array(3);
    var rString = HString[1]+HString[2];
    result[0] = parseInt(rString,16);
    var gString = HString[3]+HString[4];
    result[1] = parseInt(gString,16);
    var bString = HString[5]+HString[6];
    result[2] = parseInt(bString,16);
    return result;
}

function getPresentSecond()         //获取自程序开始的运行时间（秒）
{
    var date = new Date();
    return date.getHours()*3600+date.getMinutes()*60+date.getSeconds()+date.getMilliseconds()/1000;
}